/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package z.h.w.jar.data.time;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import z.h.w.jar.data.time.period.Period;
import z.h.w.jar.kit.method.Num;
import z.h.w.jar.kit.method.To;

/**
 * 时间的属性
 *
 * @author EnzoZhong
 */
public enum Attr {

      /**
       * 世纪
       */
      CENTURY,
      /**
       * 天
       */
      DAY,
      /**
       * 凌晨，上午，中午，下午，夜晚
       */
      EANPN,
      /**
       * 年代
       */
      ERA,
      /**
       * 星座
       */
      HOROSCOPE,
      /**
       * 小时
       */
      HOUR,
      /**
       * 毫秒
       */
      MILLISECOND,
      /**
       * 分钟
       */
      MINUTE,
      /**
       * 月份
       */
      MONTH,
      /**
       * 季节
       */
      SEASON,
      /**
       * 秒
       */
      SECOND,
      /**
       * 获取属性，周
       */
      WEEK,
      /**
       *
       */
      YEAR,
      /**
       *
       */
      ZODIAC;
      public static Map<Integer[] , String> horoscopeMap = createHoroscopeMap ();
      public static Map<Integer[] , String> seasonMAP = createSeasonMap ();
      public static Map<Integer[] , String> eanpnMap = createEanpnMap ();
      public static Map<Double , String> lunarMap = createLunarMap ();

      /**
       *
       * @param period
       *
       * @return
       */
//   public Map<Time , String> getFields ( Period period ) {
//      switch ( this.getType () ) {
//         case INT_CENTURY: {
//            throw new UnsupportedOperationException ( "Not supported yet." );
//         }
//         case INT_DAY: {
//            return utilGet ( period , 0.5 , Unit.DAY );
//         }
//         case INT_EANPN: {
//         }
//         case INT_ERA: {
//            throw new UnsupportedOperationException ( "Not supported yet." );
//         }
//         case INT_HOROSCOPE: {
//            return utilGet ( period , 1.0 , Unit.DAY );
//         }
//         case INT_HOUR: {
//            return utilGet ( period , 0.5 , Unit.HOUR );
//         }
//         case INT_MILLISECOND: {
//            throw new UnsupportedOperationException ( "Not supported yet." );
//         }
//         case INT_MINUTE: {
//            return utilGet ( period , 0.5 , Unit.MINUTE );
//         }
//         case INT_MONTH: {
//            return utilGet ( period , 0.5 , Unit.MONTH );
//         }
//         case INT_SESASON: {
//            return utilGet ( period , 1.0 , Unit.WEEK );
//         }
//         case INT_SECOND: {
//            return utilGet ( period , 0.5 , Unit.SECOND );
//         }
//         case INT_WEEK: {
//            return utilGet ( period , 1.0 , Unit.DAY );
//         }
//         case INT_YEAR: {
//            return utilGet ( period , 0.8 , Unit.MONTH );
//         }
//         case INT_ZODIAC: {
//            return utilGet ( period , 0.8 , Unit.MONTH );
//         }
//      }
//      return null;
//   } 
      private Map<Time , String> utilGet ( Period period , Double arg , Unit unit ) {
            TimeUtil UTIL = TimeUtil.born ();
            Map<Time , String> map = new TreeMap<> ();
            Time[] dateList = UTIL.enu ( period.getStart () , period.getEnd () , arg , unit );
            for ( Time date : dateList ) {
                  map.put ( date , date.tell ( this ) );
            }
            return map;
      }

      private String mapGet ( AbstractTime date , Map<Integer[] , String> map , String regex ) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat ();
            simpleDateFormat.applyPattern ( regex );
            Set<Integer[]> key = map.keySet ();
            for ( Integer[] minMax : key ) {
                  String strNum = simpleDateFormat.format ( date );
                  Integer intNum = Integer.parseInt ( strNum );
                  if ( Num.inRang ( minMax , intNum ) ) {
                        return map.get ( minMax );
                  }
            }
            return null;
      }

      private static Map<Integer[] , String> createEanpnMap () {
            Map<Integer[] , String> map = new HashMap<> ( 6 );
            map.put ( To.objs2Array ( 0 , 559 ) , "EM" );//凌晨
            map.put ( To.objs2Array ( 600 , 1059 ) , "AM" );//上午
            map.put ( To.objs2Array ( 1100 , 1359 ) , "MN" );//中午
            map.put ( To.objs2Array ( 1400 , 1859 ) , "PM" );//下午
            map.put ( To.objs2Array ( 1900 , 2359 ) , "NT" );//晚上
            return map;
      }

      private static Map<Integer[] , String> createHoroscopeMap () {
            Map<Integer[] , String> map = new HashMap<> ( 14 );
            map.put ( To.objs2Array ( 101 , 109 ) , "Capricorn" );//摩羯座
            map.put ( To.objs2Array ( 120 , 218 ) , "Aquarius" );//水瓶
            map.put ( To.objs2Array ( 219 , 320 ) , "Piscis" );//双鱼座
            map.put ( To.objs2Array ( 321 , 419 ) , "Aries" );//白羊座
            map.put ( To.objs2Array ( 420 , 520 ) , "Halcyone" );//金牛座
            map.put ( To.objs2Array ( 521 , 621 ) , "Gemini" );//双子座
            map.put ( To.objs2Array ( 622 , 722 ) , "Cancer" );//巨蟹座
            map.put ( To.objs2Array ( 723 , 822 ) , "Leo" );//狮子座
            map.put ( To.objs2Array ( 823 , 922 ) , "Virgo" );//处女座
            map.put ( To.objs2Array ( 923 , 1023 ) , "Libra" );//天秤座
            map.put ( To.objs2Array ( 1024 , 1122 ) , "Scorpio" );//天蝎座
            map.put ( To.objs2Array ( 1123 , 1221 ) , "Sagittarius" );//射手座
            map.put ( To.objs2Array ( 1222 , 1231 ) , "Capricorn" );//摩羯座
            return map;
      }

      private static Map<Integer[] , String> createSeasonMap () {
            Map<Integer[] , String> map = new HashMap<> ( 6 );
            map.put ( To.objs2Array ( 101 , 321 ) , "Winter" );
            map.put ( To.objs2Array ( 322 , 622 ) , "Spring" );
            map.put ( To.objs2Array ( 623 , 923 ) , "Summer" );
            map.put ( To.objs2Array ( 924 , 1222 ) , "Autumn" );
            map.put ( To.objs2Array ( 1223 , 1231 ) , "Winter" );
            return map;
      }

      private static Map<Double , String> createLunarMap () {
            Map<Double , String> lunar = new HashMap<> ( 13 );
            lunar.put ( 4.0 , "Mouse" );
            lunar.put ( 5.0 , "Ox" );
            lunar.put ( 6.0 , "Tiger" );
            lunar.put ( 7.0 , "Rabbit" );
            lunar.put ( 8.0 , "Loong" );
            lunar.put ( 9.0 , "Snake" );
            lunar.put ( 10.0 , "Horse" );
            lunar.put ( 11.0 , "Sheep" );
            lunar.put ( 0.0 , "Monkey" );
            lunar.put ( 1.0 , "Chicken" );
            lunar.put ( 2.0 , "Dog" );
            lunar.put ( 3.0 , "Pig" );
            return lunar;
      }

}
